package com.seele.tigerwallet.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seele.tigerwallet.R;
import com.seele.tigerwallet.model.ContactsModel;
import com.seele.tigerwallet.ui.utils.TypefaceUtils;

public class ContactsAdapter extends BaseQuickAdapter<ContactsModel, BaseViewHolder> {

    public ContactsAdapter(int layoutResId) {
        super(layoutResId);
    }

    public OnItemClickListener mListener;

    public void setonItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;

    }

    public interface OnItemClickListener {
        void onDeleteClick(int position, ContactsModel item);

        void onItemClick(int position, ContactsModel item);

        void onUpdateClick(int position, ContactsModel item);

    }

    @Override
    protected void convert(final BaseViewHolder helper, final ContactsModel item) {

        if (!TextUtils.isEmpty(item.lastname)) {
            helper.setText(R.id.name_tv, item.getLastname());
        }

        if (!TextUtils.isEmpty(item.firstname)) {
            helper.setText(R.id.name_tv, item.getFirstname());
        }
        if (!TextUtils.isEmpty(item.toaddr)) {

            helper.setText(R.id.address_tv, item.toaddr);
        }

//        TextView address_tv = helper.getView(R.id.address_tv);
//        TypefaceUtils.setCenturyGothicBold(address_tv, mContext);
        TextView delete = helper.getView(R.id.delete);
        RelativeLayout item_rv = helper.getView(R.id.item);

        TextView update = helper.getView(R.id.update);




        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mListener) {
                    mListener.onDeleteClick(helper.getPosition(), item);
                }

            }
        });
        item_rv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mListener) {
                    mListener.onItemClick(helper.getPosition(), item);
                }
            }
        });

        update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mListener) {
                    mListener.onUpdateClick(helper.getPosition(), item);
                }
            }
        });


    }
}
